<template>
  <div class="dashboard-editor-container">
    <!-- <github-corner class="github-corner" />-->

    <panel-group @handleSetLineChartData="handleSetLineChartData" />

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <el-radio-group v-model="dateRange" class="filter-item" size="medium">
        <el-radio-button label="thisWeek">本周</el-radio-button>
        <el-radio-button label="thisMonth">本月</el-radio-button>
        <el-radio-button label="lastWeek" >上周</el-radio-button>
        <el-radio-button label="lastMonth">上月</el-radio-button>

      </el-radio-group>
      <line-chart :chart-data="lineChartData" />
    </el-row>

    <!--    <el-row :gutter="32">-->
    <!--      <el-col :xs="24" :sm="24" :lg="8">-->
    <!--        <div class="chart-wrapper">-->
    <!--          <raddar-chart />-->
    <!--        </div>-->
    <!--      </el-col>-->
    <!--      <el-col :xs="24" :sm="24" :lg="8">-->
    <!--        <div class="chart-wrapper">-->
    <!--          <pie-chart />-->
    <!--        </div>-->
    <!--      </el-col>-->
    <!--      <el-col :xs="24" :sm="24" :lg="8">-->
    <!--        <div class="chart-wrapper">-->
    <!--          <bar-chart />-->
    <!--        </div>-->
    <!--      </el-col>-->
    <!--    </el-row>-->

  </div>
</template>

<script>
// import GithubCorner from '@/components/GithubCorner'
import PanelGroup from './components/PanelGroup'
import LineChart from './components/LineChart'
import RaddarChart from './components/RaddarChart'
import PieChart from './components/PieChart'
import BarChart from './components/BarChart'
import TransactionTable from './components/TransactionTable'
import TodoList from './components/TodoList'
import BoxCard from './components/BoxCard'

import { order, orderAmount, customerRange, cleanerRange } from '@/api/main'
const lineChartSetting = {
  order: {
    config: [{
      col: 'dateValue',
      stack: '1',
      colName: '订单总数统计'
    }, {
      col: 'dateValue2',
      stack: '2',
      colName: '取消订单数统计'
    }],
    xAxisCol: 'dateStr',
    data: []
  },
  orderAmount: {
    config: [{
      col: 'dateValue',
      stack: '1',
      colName: '订单金额统计'
    }, {
      col: 'dateValue2',
      stack: '2',
      colName: '未支付金额统计'
    }],
    xAxisCol: 'dateStr',
    data: []
  },
  customerRange: {
    config: [{
      col: 'dateValue',
      stack: '1',
      colName: '客户数'
    }, {
      col: 'dateValue2',
      stack: '2',
      colName: '注册客户数'
    }],
    xAxisCol: 'dateStr',
    data: []
  },
  cleanerRange: {
    config: [{
      col: 'dateValue',
      stack: '1',
      colName: '保洁员注册数'
    }],
    xAxisCol: 'dateStr',
    data: []
  }
}

export default {
  name: 'DashboardAdmin',
  components: {
    // GithubCorner,
    PanelGroup,
    LineChart,
    RaddarChart,
    PieChart,
    BarChart,
    TransactionTable,
    TodoList,
    BoxCard
  },
  data() {
    return {
      lineChartData: {},
      dateRange: 'thisWeek',
      type: 'order'
    }
  },
  watch: {
    dateRange(val) {
      this.initChartData()
    },
    type(val) {
      this.initChartData()
    }
  },
  mounted() {
    this.initChartData()
  },
  methods: {
    handleSetLineChartData(type) {
      this.type = type
    },
    initChartData() {
      if (this.type === 'order') {
        order(this.dateRange).then(({ data, code, msg }) => {
          if (data.length && code === 0) {
            lineChartSetting.order.data = data
            this.lineChartData = lineChartSetting.order
          }
        })
      }
      if (this.type === 'orderAmount') {
        orderAmount(this.dateRange).then(({ data, code, msg }) => {
          if (data.length && code === 0) {
            lineChartSetting.orderAmount.data = data
            this.lineChartData = lineChartSetting.orderAmount
          }
        })
      }
      if (this.type === 'customerRange') {
        customerRange(this.dateRange).then(({ data, code, msg }) => {
          if (data.length && code === 0) {
            lineChartSetting.customerRange.data = data
            this.lineChartData = lineChartSetting.customerRange
          }
        })
      }
      if (this.type === 'cleanerRange') {
        cleanerRange(this.dateRange).then(({ data, code, msg }) => {
          if (data.length && code === 0) {
            lineChartSetting.cleanerRange.data = data
            this.lineChartData = lineChartSetting.cleanerRange
          }
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
  .dashboard-editor-container {
    padding: 32px;
    background-color: rgb(240, 242, 245);
    position: relative;

    .github-corner {
      position: absolute;
      top: 0px;
      border: 0;
      right: 0;
    }

    .chart-wrapper {
      background: #fff;
      padding: 16px 16px 0;
      margin-bottom: 32px;
    }
  }

  @media (max-width:1024px) {
    .chart-wrapper {
      padding: 8px;
    }
  }
</style>
